package alert;

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class AlertExerciseTest {
	static WebDriver driver;
	@BeforeClass
	public static void setup(){
		driver = new FirefoxDriver();
		driver.get("http://compendiumdev.co.uk/selenium/alerts.html");
	}
	@AfterClass
	public static void closeDriver(){
		driver.quit();
	}
	@Test
	public void alertBoxTest() {
		
		WebElement alertBox = driver.findElement(By.cssSelector("#alertexamples"));
		
		//WebElement promptBox = driver.findElement(By.cssSelector("#promptexample"));
		
		alertBox.click();
		
		String textOnAlert = driver.switchTo().alert().getText();
		assertEquals("","I am an alert box!",textOnAlert);
		
		
		driver.switchTo().alert().accept();
		
		
		//promptBox.click();
		//assertEquals("","I am an alert box!",driver.switchTo().alert().getText());
		
	}
	@Test
	public void confirmBoxTest(){
		WebElement confirmBox = driver.findElement(By.cssSelector("#confirmexample"));
		WebElement confirmreturn = driver.findElement(By.cssSelector("#confirmreturn"));
		
		confirmBox.click();
		String textOnConfirm = driver.switchTo().alert().getText();
		assertEquals("","I am a confirm alert",textOnConfirm);
		
		driver.switchTo().alert().accept();
		assertEquals("","true",confirmreturn.getText());
		
		
		driver.findElement(By.cssSelector("html")).click();
		confirmBox.click();
		driver.switchTo().alert().dismiss();
		assertEquals("","false",confirmreturn.getText());
	}
	

}
